package org.app.appjson.reader.constructor;

/**
 * 对象构造器
 * 可以直接创建外部类、静态内部类、非静态内部类的实例
 * 来源：Gson
 * @param <T> 泛型参数
 * @author lizhongsi
 * @version 1.0
 * @since 1.0
 */
public class ObjectConstructor<T> {

    private final UnsafeAllocator unsafeAllocator = UnsafeAllocator.create();

    public T construct(Class<?> rawType) {
        try {
            return (T) unsafeAllocator.newInstance(rawType);
        } catch (Exception e) {
            throw new RuntimeException(("Unable to invoke no-args constructor for " + rawType.getName() + ". "
                    + "Registering an InstanceCreator for this type may fix this problem."), e);
        }
    }
}
